package com.citi.xylophone.phoneEmulator.view.listener;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;

import com.citi.xylophone.phoneEmulator.global.GlobalSwap;
import com.citi.xylophone.phoneEmulator.model.xml.ConfigSource;
import com.citi.xylophone.phoneEmulator.model.xml.Param;
import com.citi.xylophone.phoneEmulator.view.MainPanelview;

public class ButtonCallListener implements ActionListener {

	private MainPanelview mainPanelview;
	
	
	public ButtonCallListener(MainPanelview mainPanelview) {
		super();
		this.mainPanelview = mainPanelview;
	}


	public void actionPerformed(ActionEvent actionevent) {	
		
		List<Param> params = new ArrayList<Param>();
		
		try {
			
			for (ConfigSource configSource:GlobalSwap.getConfig().getDestinationList()){
				
				if (configSource.getName().equals(mainPanelview.getComboBox1().getSelectedItem())){
					
					if (configSource.getParams()!=null){
						for (Param param : configSource.getParams()){
							
							if (param.getName().equals((mainPanelview.getComboBox3().getSelectedItem()))){
								params.add(param);
							}
						}
					}
					
				}
			}
			
			
			GlobalSwap.getCoreExecutor().call(params);
			
			mainPanelview.disableActions();
			mainPanelview.enabledDial();
			
		} catch (Exception e) {			
			e.printStackTrace();
		}
		
	}
}